'use strict';

app.controller('viewRepayRecordCtrl', function($element, $scope, $state, rest, user, $rootScope, ngDialog, uiLoad, $timeout, $window) {
    var data = angular.copy($scope.ngDialogData, {});
    var token = $window.localStorage.getItem("token");

    $scope.queryParams = {
        decorateRepaymentPlanId: data.id,
    };
    $scope.$on('msg2', function(e, msg) {
        $scope.confirm({});
    });

    $scope.tableViewRepayDatas = {
        "sAjaxSource": "/tenancy-sys/admin/decorateOrderInfo/transactionQuery",
        "dom": "tr",
        "aoColumns": [{
            "sWidth": "120px",
            "bAutoWidth": false,
            "mDataProp": "record",
            "sTitle": "支付交易流水号",
            "sDefaultContent": "",
            "sClass": "center",
        }, {
            "mDataProp": "tradeNo",
            "sTitle": "支付交易号",
            "sDefaultContent": "",
            "sClass": "center"
        }, {
            "mDataProp": "payAmount",
            "sTitle": "交易金额",
            "sDefaultContent": "",
            "sClass": "center"
        }, {
            "mDataProp": "payChannel",
            "sTitle": "支付渠道",
            "sDefaultContent": "",
            "sClass": "center"
        }, {
            "mDataProp": "payStatus",
            "sTitle": "支付状态",
            "sDefaultContent": "",
            "sClass": "center"
        }, {
            "mDataProp": "paymentDate",
            "sTitle": "交易时间",
            "sDefaultContent": "",
            "sClass": "center"
        }],
        "fnRowCallback": function(nRow, aData, iDisplayIndex) {

            if (aData.stageStatus == "FIRSTTRIAL") {
                var stageStatus = "初审";
            } else if (aData.stageStatus == "DECORATEASSESSMENT") {
                var stageStatus = "装修评估";
            } else if (aData.stageStatus == "JUDGMENT") {
                var stageStatus = "终审";
            } else if (aData.stageStatus == "JUDGMENTREPETITION") {
                var stageStatus = "高管审核";
            }

            if (aData.orderProcessStatus == "OrderWaitReview") {
                var statusStr = "订单待审核";
            } else if (aData.orderProcessStatus == "OrderEffective") {
                var statusStr = "订单已通过";
            } else if (aData.orderProcessStatus == "OrderCancelled") {
                var statusStr = "订单未通过";
            } else if (aData.orderProcessStatus == "OrderRepayment") {
                var statusStr = "订单还款中";
            } else if (aData.orderProcessStatus == "OrderIsOver") {
                var statusStr = "订单已完结";
            }

            $(nRow).find(".operateStatus").empty().append(statusStr);
            $(nRow).find(".houseStatus1").empty().append(stageStatus);


        },
        "fnDrawCallback": function(oSettings) {

        },
        "fnServerParams": function(aoData) {
            // $scope.queryParams.decorateRepaymentPlanId = data.id;
            aoData.push({
                'name': 'queryParams',
                'value': $scope.queryParams,
            });
            return aoData;
        },
        "fnServerData": function(sSource, aData, fnCallback, dataTableObject) {
            //自定义给datatables传递的参数
            var obj = dataTableObject.oAjaxData,
                _baseParams = {
                    // 'page': obj.iDisplayStart / obj.iDisplayLength + 1,
                    // 'rows': obj.iDisplayLength,
                    // 'search': 'false',
                    // 'nd': '1494221804416',
                };

            var __data = angular.extend({}, _baseParams, obj.queryParams);
            rest.decoJava({
                type: "post",
                url: sSource,
                data: __data,
                beforeSend: function(request) {
                    request.setRequestHeader("token", token);
                },
                success: function(data) {
                    $scope.myDatas = data;
                    var data1 = {
                        'aaData': data.result,
                        // 'sEcho': obj.sEcho,
                        // 'iTotalDisplayRecords': data.result.page.recordCount,
                        // 'iTotalRecords': data.records,
                    };
                    fnCallback(data1);
                }
            });
        }
    };

    $scope.initRepayFinish = function(dataTable) {
        $scope.viewRepayTable = dataTable;
    }
});